//
//  CommentView.m
//  项目三
//
//  Created by rimi1 on 2016/12/12.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "CommentView.h"

static NSInteger spacing_ = 10;

@implementation CommentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.img];
        [self addSubview:self.name];
        [self addSubview:self.foodLabel];
        [self addSubview:self.foodLine];
        [self addSubview:self.food];
        [self addSubview:self.stepLabel];
        [self addSubview:self.stepLine];
        [self addSubview:self.stepContent];
        [self addSubview:self.commentLabel];
    }
    return self;
}

- (void)initHeightWithImgHeight:(CGFloat)imgHeight step:(NSString *)step {
    CGRect imgRect = self.img.frame;
    imgRect.size.height = imgHeight;
    self.img.frame = imgRect;
    
    CGRect nameRect = self.name.frame;
    nameRect.origin.y = CGRectGetMaxY(self.img.frame) + spacing_ * 2;
    self.name.frame = nameRect;
    
    CGRect foodLabel = self.foodLabel.frame;
    foodLabel.origin.y = CGRectGetMaxY(self.name.frame) + spacing_ * 2;
    self.foodLabel.frame = foodLabel;
    
    CGRect foodLine = self.foodLine.frame;
    foodLine.origin.y = CGRectGetMaxY(self.foodLabel.frame) + spacing_;
    self.foodLine.frame = foodLine;
    
    CGRect foodRect = self.food.frame;
    foodRect.origin.y = CGRectGetMaxY(self.foodLine.frame) + spacing_;
    self.food.frame = foodRect;
    [self.food sizeToFit];
    
    CGRect sRect = self.stepLabel.frame;
    sRect.origin.y = CGRectGetMaxY(self.food.frame) + spacing_ * 2 + spacing_/2;
    self.stepLabel.frame = sRect;
    
    CGRect stepLine = self.stepLine.frame;
    stepLine.origin.y = CGRectGetMaxY(self.stepLabel.frame) + spacing_;
    self.stepLine.frame = stepLine;
    
    CGRect sContentRect = self.stepContent.frame;
    sContentRect.origin.y = CGRectGetMaxY(self.stepLine.frame) + spacing_/2;
    self.stepContent.frame = sContentRect;
    self.stepContent.text = step;
    [self.stepContent sizeToFit];
    
    CGRect commentLabel = self.commentLabel.frame;
    commentLabel.origin.y = CGRectGetMaxY(self.stepContent.frame) + spacing_ * 2;
    self.commentLabel.frame = commentLabel;
    
    CGRect selfRect = self.frame;
    selfRect.size.height = CGRectGetMaxY(self.commentLabel.frame);
    self.frame = selfRect;
}

#pragma mark - get

- (UIImageView *)img {
    
    if (!_img) {
        
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, kWIDTH, WXQAdaptionWidth(220))];
        
    }
    return _img;
}

- (UILabel *)name {
    
    if (!_name) {
        
        CGFloat height = WXQAdaptionHeight(20);
        _name = [[UILabel alloc] initWithFrame:CGRectMake(spacing_, CGRectGetMaxY(self.img.frame) + spacing_ * 2, kWIDTH - spacing_ * 2, height)];
        _name.font = [UIFont boldSystemFontOfSize:height];
        _name.textAlignment = NSTextAlignmentCenter;
        
    }
    return _name;
}

- (UILabel *)foodLabel {
    
    if (!_foodLabel) {
        
        CGFloat height = WXQAdaptionHeight(19);
        _foodLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.name.frame) + spacing_ * 2, CGRectGetWidth(self.name.bounds), height)];
        _foodLabel.font = [UIFont boldSystemFontOfSize:height];
        _foodLabel.text = @"材料";
        
    }
    return _foodLabel;
}

- (UIView *)foodLine {
    
    if (!_foodLine) {
        
        _foodLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.foodLabel.frame) + spacing_, kWIDTH, 1)];
        _foodLine.backgroundColor = [UIColor blackColor];
        
    }
    return _foodLine;
}

- (UILabel *)food {
    
    if (!_food) {
        
        CGFloat height = WXQAdaptionHeight(17);
        _food = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.foodLine.frame) + spacing_, CGRectGetWidth(self.name.bounds), height * 2)];
        _food.numberOfLines = 0;
        _food.font = [UIFont systemFontOfSize:height];
        
    }
    return _food;
}

- (UILabel *)stepLabel {
    
    if (!_stepLabel) {
        
        CGFloat height = WXQAdaptionHeight(19);
        _stepLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.food.frame), CGRectGetMaxY(self.food.frame) + spacing_ * 2, CGRectGetWidth(self.food.bounds), height)];
        _stepLabel.text = @"步骤和心得";
        _stepLabel.font = [UIFont boldSystemFontOfSize:height];
        
    }
    return _stepLabel;
}

- (UIView *)stepLine {
    
    if (!_stepLine) {
        
        _stepLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.stepLabel.frame) + spacing_, kWIDTH, 1)];
        _stepLine.backgroundColor = [UIColor blackColor];
        
    }
    return _stepLine;
}

- (UILabel *)stepContent {
    
    if (!_stepContent) {
        
        _stepContent = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.stepLabel.frame), CGRectGetMaxY(self.stepLine.frame) + spacing_, CGRectGetWidth(self.stepLabel.bounds), 0)];
        _stepContent.numberOfLines = 0;
        _stepContent.font = [UIFont systemFontOfSize:WXQAdaptionHeight(17)];
        
    }
    return _stepContent;
}

- (UILabel *)commentLabel {
    
    if (!_commentLabel) {
        
        _commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWIDTH, 44)];
        _commentLabel.backgroundColor = kCOLOR_RGB(235, 235, 235, 1);
        _commentLabel.textAlignment = NSTextAlignmentCenter;
        _commentLabel.text = @"评论列表";
        
    }
    return _commentLabel;
}

@end













